﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LiveFX.Client;
using LiveFrameworkExplorer.Plugins.LiveItemEditor;

namespace LiveFrameworkExplorer.Plugins
{
    public class CreateLiveItemPlugin : IPlugin, IPluginItem
    {
        private ILFEBase _lfeBase = null;

        #region IPlugin Members

        public void Init(ILFEBase lfeBase)
        {
            _lfeBase = lfeBase;
        }

        public List<Type> GetTypes()
        {
            return new List<Type>() { 
                typeof(object)
            };
        }

        public string GetMenuItemLabel()
        {
            return "Add a LiveItem";
        }

        public System.Drawing.Image GetMenuItemImage()
        {
            return LiveFrameworkExplorer.Properties.Resources.NewDocument;
        }

        public bool CheckItem<TMeshItem, TResource>(object item)
            where TMeshItem : Microsoft.LiveFX.Client.LiveItem<TResource>, new()
            where TResource : Microsoft.LiveFX.ResourceModel.Resource, new()
        {
            return item is LiveItemCollection<TMeshItem, TResource>;
        }

        public void OpenPlugin<TMeshItem, TResource>(object item, object parentItem)
            where TMeshItem : Microsoft.LiveFX.Client.LiveItem<TResource>, new()
            where TResource : Microsoft.LiveFX.ResourceModel.Resource, new()
        {
            TMeshItem newItem = new TMeshItem();
            var collection = item as LiveItemCollection<TMeshItem, TResource>;
            collection.Add(ref newItem);
            object tmpObject = null;
            var window = _lfeBase.CreateWindowToolbox(this, typeof(ucLiveItemEditor).FullName, "Live Mesh Editor", ref tmpObject);
            (tmpObject as ucLiveItemEditor).SetObject<TMeshItem, TResource>(_lfeBase, newItem);
            window.Visible = true;
        }

        #endregion
    }
}
